﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using BUS;
namespace GUI
{
    public class UserAccount
    {
        private static UserAccount useraccount;
        private AccountBL userBL;
        private AccountDTO user;
        private UserAccount()
        {
            userBL = new AccountBL();
        }

        public static UserAccount getUser()
        {
            if (useraccount == null)
                useraccount = new UserAccount();
            return useraccount;
        }

        public int CheckUser(string name, string pass) 
        {
            user = new AccountDTO();
            List<AccountDTO> list = userBL.Custummer_SelectByUserName(name);
            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].Password == pass)
                {
                    user = list[i];
                    return 1;
                }
            }
            return 0;
        }

        public int getUserID()
        {
            return user.AccountID;
        }

        public int isAdmin()
        {
            if (user.Type == 1)
                return 1;
            return 0;
        }
    }
}
